package com.kh.pajx.sop.service.user.impl;

import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.kh.pajx.sop.base.BaseServiceImpl;
import com.kh.pajx.sop.dao.user.ISysInsideUserDao;
import com.kh.pajx.sop.domain.PageBean;
import com.kh.pajx.sop.domain.SysInsideUser;
import com.kh.pajx.sop.service.user.ISysInsideUserService;
import com.kh.pajx.sop.util.page.QueryHelper;
import com.kh.pajx.sop.util.security.encoder.Md5PwdEncoderUtil;

/**
 * 内部用户信息业务逻辑实体类
 * @author:	azzcsimp
 * @Createdate:	2014年7月21日 上午9:45:26
 */
@Service
@Transactional
public class SysInsideUserServiceImpl extends BaseServiceImpl<SysInsideUser> implements ISysInsideUserService {

	@Resource
	private ISysInsideUserDao sysInsideUserDao;
	
	// ==>1.ISysInsideUserService重载方法
	
	/**
	 * @see com.kh.pajx.sop.service.user.ISysInsideUserService#findUserByGroup(java.lang.String)
	 */
	@Override
	public List<SysInsideUser> findUserByGroup(String groupCode) throws Exception {
		return findUserByGroup(groupCode, 1);
	}
	
	/**
	 * @see com.kh.pajx.sop.service.user.ISysInsideUserService#findUserByGroup(java.lang.String, int)
	 */
	@Override
	public List<SysInsideUser> findUserByGroup(String groupCode, int userStatus) throws Exception {
		return sysInsideUserDao.findUserByGroup(groupCode, userStatus);
	}
	
	// ==>2.IBaseService重载方法
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	// =========================以下为需要整理或废弃方法===================================	
	
	@Override
	public boolean checkPhone(String phone,String uId){
		List<SysInsideUser> list = sysInsideUserDao.getUserByPhone(phone);
		if(list!=null && list.size()>0){
			for (SysInsideUser sysInsideUser : list) {
				if(sysInsideUser.getIsuId().equals(uId)){
					return true;
				}
			}
			return false;
		}else{
			return true;
		}
	}
	
	@Override
	public boolean checkPhone(String phone){
		List<SysInsideUser> list = sysInsideUserDao.getUserByPhone(phone);
		if(list!=null && list.size()>0){
			return false;
		}else{
			return true;
		}
	}
	
	
	/**
	 * 添加内部用户信息
	 * @see com.kh.pajx.sop.base.BaseServiceImpl#save(java.lang.Object)
	 */
	@Override
	public void save(SysInsideUser insideUser) {
		sysInsideUserDao.save(insideUser);
	}
	
	/**
	 * 更新内部用户信息
	 * @see com.kh.pajx.sop.base.BaseServiceImpl#update(java.lang.Object)
	 */
	@Override
	public void update(SysInsideUser insideUser) {
		sysInsideUserDao.update(insideUser);
	}
	
	/**
	 * 删除内部用户信息
	 * @see com.kh.pajx.sop.base.BaseServiceImpl#delete(java.lang.String)
	 */
	@Override
	public void delete(String uuid) {
		sysInsideUserDao.delete(uuid);
	}
	
	/**
	 * 获取内部用户信息
	 * @see com.kh.pajx.sop.base.BaseServiceImpl#getById(java.lang.String)
	 */
	@Override
	public SysInsideUser getById(String uuid) {
		return sysInsideUserDao.getById(uuid);
	}
	
	/**
	 * 查询所有用户信息列表
	 * @see com.kh.pajx.sop.base.BaseServiceImpl#findAll()
	 */
	@Override
	public List<SysInsideUser> findAll() {
		return sysInsideUserDao.findAll();
	}
	
	/**
	 * 分页获取用户信息列表
	 * @see com.kh.pajx.sop.base.BaseServiceImpl#getPageBean(int, int, com.kh.pajx.sop.util.page.QueryHelper)
	 */
	@Override
	public PageBean getPageBean(int pageNum, int pageSize,
			QueryHelper queryHelper) {
		return sysInsideUserDao.getPageBean(pageNum, pageSize, queryHelper);
	}
	
	/**
	 * 用户登录
	 * @see com.kh.pajx.sop.service.user.ISysInsideUserService#login(java.lang.String, java.lang.String)
	 */
	@Override
	public SysInsideUser login(String account, String password) {
		return sysInsideUserDao.getUserByAccountAndPassword(StringUtils.trim(account), Md5PwdEncoderUtil.encrytion(StringUtils.trim(password)));
	}
	
	/**
	 * 
	 * @see com.kh.pajx.sop.service.user.ISysInsideUserService#getUserByGroupCode(java.lang.String)
	 */
	@Override
	public List<SysInsideUser> getUserByGroupCode(String groupCode) {
		return sysInsideUserDao.getUserByGroupCode(groupCode);
	}
	
	@Override
	public List<SysInsideUser> getUserByGroupCode(String groupCode,int flag) {
		return sysInsideUserDao.getUserByGroupCode(groupCode, flag);
	}
	
	/**
	 * 
	 * @see com.kh.pajx.sop.service.user.ISysInsideUserService#getUserByRoleCode(java.lang.String)
	 */
	@Override
	public List<SysInsideUser> getUserByRoleCode(String roleCode) {
		return sysInsideUserDao.getUserByRoleCode(roleCode);
	}
	
	@Override
	public List<SysInsideUser> getUserByRoleCode(String roleCode, int flag) {
		return sysInsideUserDao.getUserByRoleCode(roleCode, flag);
	}
	@Override
	public List<SysInsideUser> getUserByRoleCode(String roleCode, int flag,String deptCode) {
		return sysInsideUserDao.getUserByRoleCode(roleCode, flag ,deptCode);
	}
	/**
	 * 
	 * @see com.kh.pajx.sop.service.user.ISysInsideUserService#getUserByDeptCode(java.lang.String)
	 */
	@Override
	public List<SysInsideUser> getUserByDeptCode(String deptCode) {
		return sysInsideUserDao.getUserByDeptCode(deptCode);
	}
	
	@Override
	public List<SysInsideUser> getUserByDeptCode(String deptCode, int flag) {
		return sysInsideUserDao.getUserByDeptCode(deptCode, flag);
	}
	
	@Override
	public long countUserByRoleCode(String usrCode) {
		return sysInsideUserDao.countUserByRoleCode(usrCode);
	};
	
	@Override
	public long countUserByDeptCode(String deptCode) {
		return sysInsideUserDao.countUserByDeptCode(deptCode);
	}
}
